package cn.wolfcode.crm.util;


import cn.wolfcode.crm.domain.Employee;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by Administrator on 2020/3/16.
 */
public abstract class UserContext {
	private static final String EMPLOYEE_IN_SESSION="EMPLOYEE_IN_SESSION";
	private static final String EXPRESSION_IN_SESSION="EXPRESSION_IN_SESSION";

	//将用户信息存到session中
	public static void setCurrentEmployee(Employee employee){
		getSession().setAttribute(EMPLOYEE_IN_SESSION,employee);
	}
	//从session中拿用户信息
	public static Employee getCurrentEmployee(){
		return (Employee)getSession().getAttribute(EMPLOYEE_IN_SESSION);
	}
	//通过工具类拿到session
	public static HttpSession getSession(){
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		return requestAttributes.getRequest().getSession();
	}
	//将权限信息存到session中
	public static void setCurrentExpression(List<String> expression){
		getSession().setAttribute(EXPRESSION_IN_SESSION,expression);
	}
	//从session中拿权限信息
	public static List<String> getCurrentExpression(Employee employee){
		return (List<String>)getSession().getAttribute(EXPRESSION_IN_SESSION);
	}
}
